#pragma once

class CFlexibleMemory
{
public:
	static CFlexibleMemory* createNewFlexibleMemory(int int_one_frame_size, int int_frame_count);

public:
	CFlexibleMemory(int int_one_frame_size, int int_frame_count);
	~CFlexibleMemory(void);

private:
	int m_int_one_frame_size;		// one frame size
	int m_int_frame_count;			// frame count
	char* m_ptr_buffers;			// buffer start point
	byte* m_lst_flags;				// using flag list

#ifndef LINUX_NAS
	CRITICAL_SECTION	m_cs_flags;
#else
	pthread_mutex_t     m_cs_flags;
#endif

protected:
	void AllocationMemory();
	void DeletionMemory();

	void Lock();
	void Unlock();

public:
	void ResetMemory();
	char* AttachBufferPointer();
	void DetachBufferPointer(char* ptr_one_frame);

};
